<?php defined('_JEXEC') or die('Restricted access'); 

// Menu
if (is_null($this->eventId)) {
	if ($this->isCrewMember && $this->eventGroup->allEventsClosed) {
		// Link to billing (excel report) - only show if all events are closed
		$this->cmealsMenu->addSeparator();
		$this->cmealsMenu->addLink("BILLING", $this->baseurl."/index.php?option=".$this->option."&view=signupreport&group_id=".$this->eventGroup->id."&tpl=excel");
	}
}
else {
	// Link to view of all events in group - only show if one specific event is being displayed
	$this->cmealsMenu->addSeparator();
	$this->cmealsMenu->addLink("SHOW_RELATED_EVENTS", $this->baseurl."/index.php?option=".$this->option."&view=signupreport&group_id=".$this->eventGroup->id);
}
echo $this->cmealsMenu->toString();
?>
<h1>
	<?php 
	JText::printf("SIGNUPREPORT"); 
	if (is_null($this->eventId)) echo " ".$this->eventGroup->description;
	?>
</h1>
<?php 
if (is_null($this->eventId) && !$this->eventGroup->allEventsClosed) {
	JText::printf("CLOSE_ALL_EVENTS_FOR_BILLING");
	echo "<br/><br/>";
}
?>
<table>
	<tr>
		<td></td>
		<?php
		foreach ($this->eventList as $event) {
			?>
			<td style="vertical-align:top;padding-right:50px" colspan="<?php echo count($event->categoryList) ?>">
				<b><?php echo JHTML::date($event->date);?></b><br/>
				<?php echo $event->description_html ?>
				<?php 
				JText::printf("HEAD_CHEF");
				echo ":&nbsp;".$event->organiser_description 
				?>
			</td>
			<?php
		} 
		?>
	</tr>
	<tr>
		<td>
			<b><?php JText::printf("MEMBER") ?></b>
		</td>
		<?php
		foreach ($this->eventList as $event) {
			foreach ($event->categoryList as $category) {
				?>
				<td>
					<b><?php JText::printf($category->display_name) ?></b>
				</td>
				<?php
			}
		}
		?>
	</tr>
	<?php
	$rowStyle[0] = "background-color:rgb(160,160,160)";
	$rowStyle[1] = "background-color:rgb(210,210,210)";
	$rowStyleId = 0;
	foreach($this->memberList as $member) {
		$rowStyleId = 1 - $rowStyleId;
		?>
		<tr>
			<td>
				<?php echo $member->name ?>
			</td>
			<?php
			foreach ($this->eventList as $event) {
				foreach ($event->categoryList as $category) {
					?>
					<td style="text-align:center;<?php echo $rowStyle[$rowStyleId]?>">
						<?php
						echo $category->participantsList[$member->id];
						?>
					</td>
					<?php 
				}
			}
			?>
		</tr>
		<?php
	}
	?>
	<tr>
		<td>
			<b><?php JText::printf("PARTICIPANTS_SUM") ?></b>
		</td>
		<?php 
		foreach ($this->eventList as $event) {
			if ($event->status >= CMeals::STATUS_CLOSED) {
				foreach ($event->categoryList as $category) {
					?>
					<td style="text-align:center;font-weight:bold">
						<?php
							echo $category->participantsSum;
						?>
					</td>
					<?php 
				}
			}
			else {
				?>
				<td colspan="<?php echo count($event->categoryList) ?>">
					<?php
					if ($this->isCrewMember && $event->status == CMeals::STATUS_OPEN) {
						// Link to signupreport with option to close event
						echo "<a href=\"".$this->baseurl."/index.php?option=".$this->option."&view=signupreport&group_id=".$event->group_id."&event_id=".$event->id."&tpl=eventform\">".JText::_("CLOSE")."...</a>";
					}
					?>
				</td>
				<?php 
			}
		}
		?>
	</tr>
</table>
<br/>&nbsp;